package com.example.demo.mapper;

import com.example.demo.entity.TestPaper;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Mapper
public interface PaperMapper {
    /**
     * 查询章节试卷
     * */
    @Select("select * from test_paper where chapter_id=#{chapter_id}")
    public TestPaper selpaper(Integer chapter_id);

    /**
     * 查询所有试卷
     * */
    @Select("SELECT c.`chapter_name`,t.* FROM test_paper AS t LEFT JOIN chapter AS c ON c.`chapter_id`=t.`chapter_id`")
    public List<TestPaper> selallpaper();
    /**
     * 增加试卷
     * */
    @Insert("insert into test_paper values(default,#{test_paper_name},0,1,#{chapter_id})")
    public int inspaper(String test_paper_name,Integer chapter_id);

    /**
     * 更改试卷
     * */
    @Update("update test_paper set test_paper_name=#{test_paper_name},chapter_id=#{chapter_id} where test_paper_id=#{test_paper_id}")
    public int updpaper(String test_paper_name,Integer chapter_id,Integer test_paper_id);

    /**
     * 删除试卷
     * */
    @Delete("delete from test_paper where test_paper_id=#{test_paper_id}")
    public int delpaper(Integer test_paper_id);

    /**
     * 改变试卷状态
     * */
    @Update("update test_paper set test_paper_status=1 where test_paper_id=#{test_paper_id}")
    public int updpastu(Integer test_paper_id);

    /**
     * 查询用户是否已经做过此章节试卷
     * */
    @Select("SELECT test_questions_id FROM record WHERE test_paper_id = #{tpid} AND user_id = #{uid}")
    public List<Integer> seltqrecord(Integer tpid, Integer uid);
    @Select("SELECT questions_options_id FROM record WHERE test_paper_id = #{tpid} AND user_id = #{uid}")
    public List<Integer> seltqrecordopid(Integer tpid, Integer uid);//选项ID
    /**
     * 查询已做试卷的试题
     * */
    @Select("SELECT test_questions_name,test_questions_id FROM test_questions WHERE test_questions_id = #{tqid}")
    List<HashMap> selrecordtqname(Integer tqid);
    /**
     * 查询已做试卷的试题的选项
     */
    @Select("SELECT questions_options_id,questions_options_content FROM questions_options WHERE test_questions_id = #{tqid}")
    public List<Map> selrtqopt(Integer tqid);


}
